package com.bdpn.ch05.controller;

import com.bdpn.ch05.pojo.SysUser;
import com.bdpn.ch05.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
    @Resource
    private UserService userService;
    @RequestMapping(value = "/login")
    public String login(String usrName , String usrPassword , Model model , HttpSession session){
        SysUser user = userService.login(usrName , usrPassword);
        if (user != null){
            session.setAttribute("loginUser" , user);
            return "main";
        }else {
            model.addAttribute("msg","用户名或密码错误，登录失败！");
            return "forward:/login.jsp";
        }
    }
}
